package com.cqs.leetcode.string;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lixqw
 * @date 2020/8/19
 */
public class PalindromicSubstrings {

    public int countSubstrings(String s) {
        char[] chars = s.toCharArray();
        if (s.length() <= 1) return s.length();
        int sum = s.length();
        for (int i = 0; i < s.length() - 1; i++) {
            for (int j = i + 1; j < s.length(); j++) {
                int l = i, r = j;
                int del = 1;
                while (l < r) {
                    if (chars[l] == chars[r]) {
                        ++l;
                        --r;
                    } else {
                        del = 0;
                        break;
                    }
                }
                sum += del;
            }
        }
        return sum;
    }

    public static void main(String[] args) {
        List<String> tests = new ArrayList<>();
        tests.add("aaa");
        tests.add("abc");
        tests.add("");
        tests.add("a");
        tests.add("ababababababacacaca");
        PalindromicSubstrings palindromic = new PalindromicSubstrings();
        tests.forEach(it -> {
            System.out.println(it + "\t" + palindromic.countSubstrings(it));
        });
    }

}
